parameters:
  - name: VSCODE_BUILD_WIN32
    type: boolean
  - name: VSCODE_BUILD_WIN32_ARM64
    type: boolean

steps:
  - task: NodeTool@0
    displayName: "Use Node.js"
    inputs:
      versionSource: fromFile
      versionFilePath: .nvmrc
      nodejsMirror: https://github.com/joaomoreno/node-mirror/releases/download

  - powershell: node build/setup-npm-registry.js $env:NPM_REGISTRY build
    condition: and(succeeded(), ne(variables['NPM_REGISTRY'], 'none'))
    displayName: Setup NPM Registry

  - powershell: |
      . azure-pipelines/win32/exec.ps1
      $ErrorActionPreference = "Stop"
      exec { npm config set registry "$env:NPM_REGISTRY" --location=project }
      # npm >v7 deprecated the `always-auth` config option, refs npm/cli@72a7eeb
      # following is a workaround for yarn to send authorization header
      # for GET requests to the registry.
      exec { Add-Content -Path .npmrc -Value "always-auth=true" }
      exec { yarn config set registry "$env:NPM_REGISTRY" }
    workingDirectory: build
    condition: and(succeeded(), ne(variables['NPM_REGISTRY'], 'none'))
    displayName: Setup NPM & Yarn

  - task: npmAuthenticate@0
    inputs:
      workingFile: build/.npmrc
    condition: and(succeeded(), ne(variables['NPM_REGISTRY'], 'none'))
    displayName: Setup NPM Authentication

  - powershell: |
      . azure-pipelines/win32/exec.ps1
      . azure-pipelines/win32/retry.ps1
      $ErrorActionPreference = "Stop"
      $env:CHILD_CONCURRENCY="1"
      retry { exec { yarn --frozen-lockfile --check-files } }
    workingDirectory: build
    displayName: Install build dependencies

  - template: ../cli/cli-win32-sign.yml@self
    parameters:
      VSCODE_CLI_ARTIFACTS:
        - ${{ if eq(parameters.VSCODE_BUILD_WIN32, true) }}:
          - unsigned_vscode_cli_win32_x64_cli
        - ${{ if eq(parameters.VSCODE_BUILD_WIN32_ARM64, true) }}:
          - unsigned_vscode_cli_win32_arm64_cli
